﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WordCloudInterface
{
    public partial class AddWord : Form
    {
        private Interface parentForm;

        public AddWord(Interface form)
        {
            this.parentForm = form;

            InitializeComponent();

            // Put save btn in the middle
            Point saveBtnLocation = this.button1.Location;
            saveBtnLocation.X = (this.Width / 2) - (this.button1.Width / 2);
            this.button1.Location = saveBtnLocation;

            // Change window upper-left icon
            this.Icon = Interface.GetProgramIcon();

            this.textBox2.Text = "1";

            // Create the ToolTip and associate with the Form container.
            ToolTip toolTip1 = new ToolTip();

            // Set up the delays for the ToolTip.
            toolTip1.AutoPopDelay = 5000;
            toolTip1.InitialDelay = 1000;
            toolTip1.ReshowDelay = 500;
            // Force the ToolTip text to be displayed whether or not the form is active.
            toolTip1.ShowAlways = true;

            toolTip1.SetToolTip(this.label2, "The number of occurences will affect the size of the word.");
            toolTip1.SetToolTip(this.textBox2, "The number of occurences will affect the size of the word.");
        }

        // Refresh error label's position
        private void RefreshErrorLabelPos()
        {
            // Set error label's position
            Point location = this.label3.Location;
            location.X = (this.Width / 2) - (this.label3.Width / 2); //horizontal
            this.label3.Location = location;
        }

        // Btn save new word
        private void button1_Click(object sender, EventArgs e)
        {
            bool invalidOccurenceNumber = false;
            if (this.textBox1.Text.Length > 0 && this.textBox2.Text.Length > 0)
            {
                try
                {
                    int val = Convert.ToInt32(this.textBox2.Text);
                    if (val >= 1 && val <= 999)
                    {
                        this.parentForm.AddNewWordManually(this.textBox1.Text, val);
                        this.Close();
                    }
                }
                catch
                {
                    invalidOccurenceNumber = true;
                }
            }
            this.label3.Text = (invalidOccurenceNumber == true ? "Invalid occurences number." : "Invalid word.");
            this.RefreshErrorLabelPos();
        }
    }
}
